import React from 'react';

export default class Row extends React.Component {

  constructor(props) {
    super(props);
    this.getRow = this.getRow.bind(this);
  }

  getRow(event) {
  	this.props.onClick(this.props.obj,(this.props.index+1));
  }

  getFommater(res,index,formatter) {
  	if(formatter) {
  		return formatter(res,index,this.props.obj[res.name]);
  	}
  	if(res.name=='index') {
  		return index+1;
  	}
  	return this.props.obj[res.name];
  }

  render() {
  	let obj = this.props.obj;
    let count = 1;
    return (
      <tr onClick={this.getRow}>
      {
      	this.props.columns.map((res,index)=>(
      		<td key={index} align={res.align?res.align:'left'} className={this.props.className+"_td"}>{this.getFommater(res,this.props.index,res.formatter)}</td>
      	))
      }
      </tr>
    );
  }
}